﻿#ifndef QMLRELAYSWITCH_H
#define QMLRELAYSWITCH_H

#include <QObject>
#include <QDebug>
#include <QCoreApplication>

#include "qmlrelayswitch_macro.h"

class QmlRelaySwitch : public QObject
{
    Q_OBJECT
public:
    explicit QmlRelaySwitch(QObject *parent = nullptr);
    static QmlRelaySwitch *getInstance();

signals:
    /***************************/
    mkswitchs(f_signal_def);
    mkswitchs(f_signal_qstr);
    /***************************/
    // define signals for Application Service
    void pushSwitchStatus2QmlSignal(int channel, int state);
    void pushSwitchStatus2QmlSerialPortSignal(int channel, int state);
    void logsPrintSignal(QString s);

    void settingsPathChanged();

public:
    /***************************/
    mkswitchs(f_func_def);
    mkswitchs(f_func_qstr);
    /***************************/
    Q_INVOKABLE bool setSwitchStatus2MainService(int channel, bool state);
    void syncSwitchStatus2Qml(int channel, bool state);
    void resetUiSwitchStatus();

public slots:
        void syncSwitchStatus2QmlSlot(QString name, QString state);

public:
    /***************************/
    typedef enum {
        e_zero,
        mkswitchs(f_enum)
        e_num
    } switch_index_t;
    /***************************/

    QString settingsPath() const;
    void setSettingsPath(const QString &newSettingsPath);

private:
    /***************************/
    mkswitchs(f_var);
    mkswitchs(f_var_property);
    mkswitchs(f_var_qstring);
    mkswitchs(f_var_property_qstr);
    /***************************/
    int  relayCount;

    QString m_settingsPath;

    void log(QString s);
    Q_PROPERTY(QString settingsPath READ settingsPath WRITE setSettingsPath NOTIFY settingsPathChanged FINAL)
};

#endif // QMLRELAYSWITCH_H
